// Created by WXX on 2021/10/8 10:05
#include "MyTree.h"

class Solution {
public:
    bool ans;

    bool isUnivalTree(TreeNode* root) {
        int val = root->val;
        ans = true;
        dfs(root, val);
        return ans;
    }

    void dfs(TreeNode* root, int val) {
        if (!root) return;
        if (root->val != val) {
            ans = false;
            return;
        }
        dfs(root->left, val);
        dfs(root->right, val);
    }
};

int main() {

    int nu = INT_MAX;
    vector<int> nums = {
            1,
            1, 1
    };
    TreeNode *root = MyTree(nums).getRoot();
    cout << Solution().isUnivalTree(root) << endl;

    return 0;
}
